/**
 * 修改密码 - 编辑页面
 * @author shixc
 * @date 2018/02/27
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        vueData = {
            isAdd: false,
            form: {
                password_: null,
                new_password_: null,
                confirm_new_password_: null
            },
            rules: {
                password_: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                new_password_: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                confirm_new_password_: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ]
            }
        }
    ;

    var PasswordEdit = app.Module.extend({
        init: function () {
            self = this;
            self._super({
                _tag: 'password'
            }, win);
        },
        updatePwd: function () {
            app.ajax({
                xurl: 'updateMyPwd',
                xdata: vueData.form,
                loading: true,
                okmsg: '密码修改成功',
                cb: function (result) {
                    if (result.ok) {
                        layer.close(layer.index);
                    }
                }
            });
        },
        _call: function (obj) {
            app.extendUpLow({
                target: vueData.form,
                res: {},
                reset: true
            });
        },
        _ready: function () {
            var vue = new Vue({
                el: '#password',
                data: vueData,
                methods: {
                    cancel: function () {
                        layer.close(layer.index);
                    },
                    sure: function () {
                        this.$refs['form'].validate(function (valid) {
                            if (valid) {
                                self.updatePwd();
                            }
                        });
                    }
                },
                watch: {},
                created: function () {
                    self._setEleIsReady('password');
                }
            });
        },
        _lazy: function () {
            this._super();
        }
    });

    return new PasswordEdit();

});